
import enumMode from "../../../em/enumMode"
import enumPatch from "../../../em/enumPatch"
import supModule from "../../../sup/supModule"
import gameMount from "./gameMount"
export default class O extends supModule {
    private static gscnt:number = 0;   //所有
    private image:number        = null;//图标
    private axleX:number        = null;//转轴
    private axleY:number        = null;//转轴
    private mount:gameMount  = null;//脚本
    constructor(image:number,x:number,ucode:any){
        super(enumMode.jymtImgeMoudle);
        this.setSpanel(enumPatch.jymtGameImg);
        this.image = image;
        this.axleX = x;
        this.mount = ucode;
        O.gscnt++;
    }
    //扩展项
    protected changeInstance():void{
        O.gscnt--;
        if(0 == O.gscnt){
            setTimeout(function(){
                let game = this.getModule("sc_jymt_game");
                game.imgfish();
            }.bind(this),0);
        }
    }
    //扩展项
    protected extendClose():void{
        this.clearScripts();
    }
    //获取图片
    public img():number{
        return this.image;
    }
    //获取图片
    public axl():number{
        return this.axleX;
    }
    //获取下标
    public getIndex(){
        return (this.axleY-1)*5+this.axleX;
    }
    //设置位置
    public setPos(pos:number){
        let lpos = this.mount.vec2resetBy(pos);
        this.node().x = lpos.x;
        this.node().y = lpos.y;
        this.axleY = Math.ceil(pos/5);
    }
    //归位起点
    public homing(){
        let wpos = this.mount.startVec2(this.axl());
        let lpos = this.mount.wvec2Tresult(wpos);
        this.node().x = lpos.x
        this.node().y = lpos.y
        this.axleY = 0;
    }
    //移向终点
    public ending(){
        //结果位置
        let elv2 = this.mount.vec2resetBy(15+this.axleX);
        //组织动画
        let a = cc.moveTo(2*(3-this.axleY),elv2);
        let b = cc.callFunc(()=>{
            this.homing();//归位
            this.ending();//终点
        });
        //终点位置
        this.node().runAction(cc.sequence(cc.delayTime(3),a,b));
    }

    //普通回弹
    public rebount(){
        let anim = this.mount.rebountAnim();
        this.node().runAction(anim);
    }
}